<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件

// 获取sign
function get_token($secret, $data)
{
    // 对数组的值按key排序
    ksort($data);
    // 生成url的形式
    $params = http_build_query($data);
    // 生成sign
    $sign = md5($params . $secret);
    return $sign;
}

//token验证
function check_token($arr)
{
    //验证token是否为空
    if (!isset($arr['token']) || empty($arr['token'])) {
        return 'Token can`t be empty';
    }
    $app_token = $arr['token']; // api传过来的token

    unset($arr['token']);
    $service_token = '';
    foreach ($arr as $key => $value) {
        $service_token .= md5($value);
    }
    $service_token = md5($service_token .config('app.login_end'));
    if ($app_token !== $service_token) {
        //$this->return_msg(1, 'Token is not correct');
        return false;
    } else {
        return true;
    }
}
